/**
 * Created by jinxs on 14-6-17.
 *
 */
var _IE = webUI_browser().ie;
var _IE8 = (_IE && webUI_browser().version == 8);
/**
 * 是否为IE6
 * @type {*|ie|boolean}
 * @private
 */
var _IEunder6 = (_IE && webUI_browser().version < 7);
var _IEunder7 = (_IE && webUI_browser().version < 8);
var _IEunder8 = (_IE && webUI_browser().version < 9);
var _IEunder9 = (_IE && webUI_browser().version < 10);
if (_IEunder6) {
    document.execCommand("BackgroundImageCache", false, true);
    var bg = 'backgroundAttachment';
    if ($('html').css(bg) !== 'fixed' && $('body').css(bg) !== 'fixed') {
        $('html').css({
            zoom: 1, // 避免偶尔出现body背景图片异常的情况
            backgroundImage: 'url(about:blank)',
            backgroundAttachment: 'fixed'
        });
    }
}
function isChinese(str) {
    if(escape(str).indexOf("%u")<0){
        return false;
    }else{
        return true;
    }
}
/**
 * 显示操作结果
 * @param success 是否成功
 * @param msg 结果消息
 */
function showResult(success, msg, errorType) {
    if (success) {
        //成功
        $.uiMessagetip.show({
            animate: true,
            panelStyle: 'ui_panel_success',
            height: 40,
            showHeader:false,
            padding: 10,
            title: '消息提示',
            content: msg,
            vertical: 'top',
            horizontal: 'center',
            timeout: 1500
        });
    } else {
        var time = 2000;
        if (errorType === undefined) {
            errorType = 'error';
        }
        else if (errorType == 'error') {
            time = 0;
        }
        $.uiMessagebox.alert({
            width: 300,
            height: 114,
            draggable:true,
            maximizable:true,
            type: errorType,
            title: '消息提示',
            content: msg,
            timeout: time
        });
    }
}
/**
 *页面初始化
 */
$(function () {
    $._ajax = $.ajax;
    $.ajax = function (opt) {
        var fn = {
            showLoading: true,
            dataType:'json',
            beforeSend: function (xhr) {
            },
            error: function (xhr, textStatus, errorThrown) {
            },
            success: function (data, textStatus) {
            }
        };
        $.extend(fn, opt || {});
        $.extend(opt, {
            cache:false,
            beforeSend: function (xhr) {
                if(fn.beforeSend(xhr)===false){
                    return false;
                }
                else if(fn.showLoading){
                    $.uiLoading.show();
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                $.uiLoading.hide();
                if (fn.error(xhr, textStatus, errorThrown) !== false) {
                    showResult(false, '服务器端错误：' + xhr.responseText);
                }
            },
            success: function (data, textStatus) {
                $.uiLoading.hide();
                if (fn.success(data, textStatus) !== false) {
                    if (!!data.message) {
                        showResult(data.success, data.message);
                    }
                }
            }
        });
        return $._ajax(opt);
    };

    $(window).unbind('.resize').bind('resize.resize', function () {
        $('body').children().each(function () {
            var elem = $(this);
            if (elem.is(':visible') || (elem.attr('closed')&&elem.attr('closed')=='false')) {
                elem.triggerHandler('_resize');
            }
        })
    });
});